<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="./Promise.js"></script>
</head>
<body>
    <h1>Class版的Promise实现【ES6标准】</h1>

    <script>
         
       // 自定义Promise类的使用
    /*
       // 直接使用Promise作为对象直接调用resolve返回来创建Promise对象
       const p1 = new Promise((resolve, reject)=>{
            // setTimeout(()=>{
            //     resolve("zhangsan");
            // },0);
            reject("zhangsan");
            //resolve("zhangsan");
       });
       const p2 = Promise.resolve("lisi");
    //    //const p2 = Promise.reject("error");
    //    const p3 = Promise.resolve("wangwu");

       p1.then(v => {
         console.log("ok", v);
         return 10;
       }).then(v => {
         console.log(v);
       }).catch(err => {
         console.log("报错，原因：", err);
       });
       
        //console.log(p2);

    */

    // 关于then的异步问题

    // 创建一个promise对象
    const p = Promise.resolve("ok");
    //const p = Promise.reject("error");

    console.log("start....");

    // 使用promise对象
    p.then(v => {
        console.log("成功", v);
    },r => {
        console.log("失败", r);
    });

    console.log("end....");





        /*
            // 构造函数版(ES5标准)
            function Demo(){

            }
            Demo.prototype.fn1 = function(){}

            Demo.fn2 = function(){}


            //class类（ES6标准）
            class Demo {

                fn1(){

                }
                static fn2(){

                }
            }

            // 使用
            new Demo().fn1();

            Demo.fn2();

            */
    </script>
</body>
</html>